
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;



namespace XFGameFramework
{

    // Fix 编码

    public class UpdateManager : MonoBehaviour
    {
          
        private static bool destroyed = false;


        #region 事件
        /// <summary>
        /// Update时调用
        /// </summary>
        public static Action onUpdate;
        /// <summary>
        /// FixedUpdate时调用
        /// </summary>
        public static Action onFixedUpdate;
        /// <summary>
        /// LateUpdate时调用
        /// </summary>
        public static Action onLateUpdate;
        #endregion


        static UpdateManager()
        { 
            #region UNITY_EDITOR
            if (!Application.isPlaying) return;
            #endregion

            if (destroyed) return;

            GameObject obj = new GameObject("UpdateManager");
            GameObject.DontDestroyOnLoad(obj);
            obj.AddComponent<UpdateManager>();
        }

        private void FixedUpdate()
        {
            onFixedUpdate?.Invoke(); 
        }

        private void Update()
        {
            onUpdate?.Invoke(); 
        }

        private void LateUpdate()
        {
            onLateUpdate?.Invoke(); 
        }

        private void OnDestroy()
        {
            destroyed = true;
        }

    }
}

